#!/usr/bin/env node

const http = require('http'),
      log  = console.log,
      url  = require('url'),
      addr = process.argv[2];

http.get(addr,(res)=>{

  //print response start line
  //http1.1 200 ok
  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);


  //print response headers
  //content length:22
  log(res.headers);


  //print response body
  //res.pipe(process.stdout);
  
  //请求回来的数据在res里封装，对于客户端是可读流
  let data = '';

  res.on('data',(chunk)=>{
    data += chunk;
  });
  res.on('end',()=>{
    log(data);
  })
});
